package com.whyx.project.openapi.controller;

import com.whyx.project.openapi.config.KafkaProducerConfig;
import com.whyx.project.openapi.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@RestController
@Api(description = "视频中间服务处理API")
public class TestController {
    private static final Logger log = LoggerFactory.getLogger(TestController.class);
    public static final String TOPIC_DISTRIBUTE_DATA   =  "distributeData";
    public static final String DISTRIBUTE_MSG_TOPIC    =  "RealtimeMediaUploadReq_Send";
    public static final String DISTRIBUTE_CMD_TOPIC    =  "RealtimeMediaUploadCmd_Send";



    @Autowired
    KafkaProducerConfig kafkaProducerConfig;

    @ApiOperation("流媒体控制")
    @CrossOrigin //允许跨域认证
    @ApiImplicitParams({
            @ApiImplicitParam(name = "controllerPath", paramType = "path", allowableValues = "web", required = true),
            @ApiImplicitParam(name = "msgoperation", value = "流媒体控制0：下发通知并上线 1：关闭视频", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "devid", value = "终端设备id", dataType = "string", paramType = "query",required = true),
            @ApiImplicitParam(name = "channel", value = "通道号", dataType = "int", paramType = "query",required = true),
            @ApiImplicitParam(name = "streamtype", value = "流媒体类型 0音视频 1视频 2音频", dataType = "int", paramType = "query",required = true)
    })
    @PostMapping(value = "/{controllerPath}/streamingMediaControl")
    public @ResponseBody
    R getElectricFence(HttpServletRequest request) throws Exception {
        R r = new R();

        String devid = request.getParameter("devid");
        int channel = Integer.parseInt(request.getParameter("channel"));
        try {
            r.put("code", "0");
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", "1");
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }


}





